package com.freightoa.sgl_login.domain

import com.freightoa.foundation.net.bean.SGLResponse
import com.freightoa.foundation.presentation.domain.BaseUseCase
import com.freightoa.sgl_login.data.datasource.database.model.Data
import com.freightoa.sgl_login.repository.LoginRepository
import javax.inject.Inject

class LoginUseCase @Inject constructor(private val loginRepository: LoginRepository) :
    BaseUseCase() {

    suspend operator fun invoke(loginName: String, loginPassword: String): Result<Data> {
        val login = loginRepository.login(loginName, loginPassword)
        val orNull = login.getOrNull() ?: return Result.failure(RuntimeException("data is null"))
        val data =
            orNull.data ?: return Result.failure(RuntimeException(login.getOrNull()?.message_en))
        return Result.success(data)
    }
}